//
//  PywSetSubAccountPwdApi.m
//  PywSdk
//
//  Created by smallwave on 16/8/30.
//  Copyright © 2016年 zero. All rights reserved.
//

#import "PywSetSubAccountPwdApi.h"
#import "AIFSetSubAccountPwdManager.h"
#import "PropertyListReformer.h"
#import "PywMBProgressHUD+Pyw.h"

@interface PywSetSubAccountPwdApi ()<ETAPIManagerCallBackDelegate>

@end

@implementation PywSetSubAccountPwdApi

- (void)requestSetSubAccountPwdWithParams:(MutableDictionary *)params
                                  success:(Successd)success
                                     fail:(Failure)fail{
    self.successd = success;
    self.failure = fail;
    
    AIFSetSubAccountPwdManager *manager = [AIFSetSubAccountPwdManager manager];
    manager.account = [params objectForKey:@"account"];
    manager.account_pwd = [params objectForKey:@"account_pwd"];
    manager.delegate = self;
    [manager loadData];
}
#pragma mark - ETAPIManagerCallBackDelegate
/**
 *  请求成功
 *
 *  @param manager <#manager description#>
 */
- (void)managerCallAPIDidSuccess:(ETApiBaseManager *)manager
{
    PropertyListReformer *reformer = [[PropertyListReformer alloc] init];
    NSDictionary *dict = [manager fetchDataWithReformer:reformer];
    [PywMBProgressHUD hideHUDForView:[UIApplication sharedApplication].keyWindow];
    
    [self setSubAccountPwdWithDict:dict];
}
/**
 *  请求失败
 *
 *  @param manager <#manager description#>
 */
- (void)managerCallApiDidFailed:(ETApiBaseManager *)manager
{
    [PywMBProgressHUD hideHUDForView:[UIApplication sharedApplication].keyWindow];
    
    if (self.failure) {
        self.failure([self errorWithCode:0]);
    }
}
/**
 *  设置登录密码 成功
 */
- (void)setSubAccountPwdWithDict:(NSDictionary *)dict{
    int resultCode = [[dict objectForKey:@"ack"] intValue];
    if (resultCode == 200) {
        
        if (self.successd) {
            self.successd(nil,nil);
        }
    }else {
        
        if (self.failure) {
            self.failure([self errorWithCode:resultCode]);
        }
    }
}

@end
